package com.spa.infrastructure.repository.service;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.spa.infrastructure.repository.condition.OrderExtDetailCondition;
import com.spa.infrastructure.repository.mapper.OrderExtDetailMapper;
import com.spa.infrastructure.repository.po.OrderExtDetailPO;
import org.springframework.stereotype.Component;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;

/**
 * domain service
 * 加单详情表(OrderExtDetail) 
 *
 * @author lig
 * @since 2024-02-21 17:11:42
 */
@Component
public class OrderExtDetailRepositoryService extends MPJBaseServiceImpl<OrderExtDetailMapper, OrderExtDetailPO> {

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    public OrderExtDetailPO queryById(Long id) {
		return getById(id);
    }

	/**
     * 分页查询
     * @return 查询结果
     */
	public Page<OrderExtDetailPO> pageListInfo(OrderExtDetailCondition condition) {
		LambdaQueryWrapper<OrderExtDetailPO> wrapper = wrapper(condition);
        return page(Page.of(condition.getCurrent(), condition.getSize()), wrapper);
    }
	
	public List<OrderExtDetailPO> listInfo(OrderExtDetailCondition condition) {
        return list(wrapper(condition));
    }

	private LambdaQueryWrapper<OrderExtDetailPO> wrapper(OrderExtDetailCondition condition) {
        LambdaQueryWrapper<OrderExtDetailPO> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ObjectUtil.isNotEmpty(condition.getOrderExtId()), OrderExtDetailPO::getOrderExtId, condition.getOrderExtId());
        wrapper.in(CollectionUtil.isNotEmpty(condition.getOrderExtIds()), OrderExtDetailPO::getOrderExtId, condition.getOrderExtIds());
        return wrapper;
    }

    public void insert(OrderExtDetailPO orderExtDetailPO) {
        save(orderExtDetailPO);
    }

    public List<OrderExtDetailPO> queryByOrderExtIds(List<Long> ids) {
        OrderExtDetailCondition condition = new OrderExtDetailCondition();
        condition.setOrderExtIds(ids);
        return list(wrapper(condition));
    }

}
